/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 * 用户输入
 * 随机产生
 * 比较并输出
 * 
 */

package lottery_in;
import java.io.*;
/**
 *
 * @author hhl
 */
public class Lottery_in {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int[] code = new int[3];
        int[] prize = new int[3];
        boolean[] result = new boolean[3];

        for(int i = 0; i<3; i++){
            code[i]=0;
            prize[i]=0;
            result[i]=false;
        }

        String s="";
        for(int i = 0; i < 3; i++){

            //gambler wager
            System.out.println("请输入3个在1~20内的号码：");
            try{
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                s = in.readLine();
            }
            catch(IOException e){}
            code[i]=Integer.parseInt(s);

            //... and produce jackpot
            while((prize[0]==prize[1])||(prize[0]==prize[2])||(prize[1]==prize[2])){
                prize[0]=Produce();
                prize[1]=Produce();
                prize[2]=Produce();
            }
        }
        //publicity
        for(int i = 0; i<3; i++){
            System.out.println("你选择的第"+(i+1)+"个号码为："+code[i]);
        }
        System.out.println("开奖信息：");
        for(int i = 0; i<3; i++){
            System.out.println((i+1)+"等奖为："+prize[i]);
        }

        // compare
        for(int i = 0; i<3; i++){
            for(int j = 0; j<3; j++){
                result[i]=Compare(code[j],prize[i]);
                if(result[i])
                    System.out.println("Congradulation! You win the "+(i+1)+" prize!");
            }
        }
        
        if(!(result[0]|result[1]|result[2]))
            System.out.println("What's a pity! You lose.");
    }
    static int Produce(){
        return (int)(Math.random()*(20-1)+1);
    }
    static boolean Compare(int lotteryNumber, int randomNumber){
        if(lotteryNumber==randomNumber)
            return true;
        return false;
    }
}
